package com.example.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.admin.entity.GenFieldVo;
import com.example.admin.entity.GenTable;
import com.example.admin.entity.GenTableVo;
import com.example.admin.mapper.GenTableMapper;
import com.example.admin.service.IGenTableColumnService;
import com.example.admin.service.IGenTableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 代码生成业务表 服务实现类
 * </p>
 *
 * @author wangkai
 * @since 2020-10-29
 */
@Service("genTableService")
public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> implements IGenTableService {

    @Autowired
    private IGenTableColumnService genTableColumnService;

    @Override
    public List<GenTableVo> selectTable(GenTableVo vo) {
        return this.baseMapper.selectTable(vo);
    }

    @Override
    public List<GenFieldVo> selectTableColumns(GenTableVo vo) {
        return this.baseMapper.selectTableColumns(vo);
    }

    @Override
    public IPage<GenTable> selectMyPage(IPage<GenTable> page, Wrapper<GenTable> queryWrapper) {
        return this.baseMapper.selectMyPage(page, queryWrapper);
    }

    @Override
    @Transactional
    public boolean removeByTableIds(List<Integer> asList) {
        if (asList != null && asList.size() > 0) {
            QueryWrapper queryWrapper = new QueryWrapper();
            queryWrapper.in("table_id", asList);
            genTableColumnService.remove(queryWrapper);
            this.removeByIds(asList);
        }
        return true;
    }

    @Override
    public GenTable getMyById(Integer id) {

        return this.baseMapper.getMyById(id);
    }
}
